package io.kiki.stack.http.feign.SpringMvcContract.encoding;

import io.kiki.stack.http.feign.RequestTemplate;

/**
 * Enables the HTTP response payload compression by specifying the {@code Accept-Encoding}
 * headers. Although this does not yet mean that the requests will be compressed, it
 * requires the remote server to understand the header and be configured to compress
 * responses. Still no all responses might be compressed based on the media type matching
 * and other factors like the response content length.
 */
public class FeignAcceptGzipEncodingInterceptor extends BaseRequestInterceptor {

    /**
     * Creates new instance of {@link FeignAcceptGzipEncodingInterceptor}.
     *
     * @param properties the encoding properties
     */
    protected FeignAcceptGzipEncodingInterceptor(FeignClientEncodingProperties properties) {
        super(properties);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void apply(RequestTemplate requestTemplate) {

        addHeader(requestTemplate, HttpEncoding.ACCEPT_ENCODING_HEADER, HttpEncoding.GZIP_ENCODING, HttpEncoding.DEFLATE_ENCODING);
    }

}
